#include "SDL/SDL.h"
#include <string>
#include "SDL/SDL_mixer.h"
#include "myaudio.h"

using namespace std;

myaudio::myaudio(char* soundfile)
{
    int audio_rate = 22050;
    Uint16 audio_format = AUDIO_S16; // 16-bit stereo
    int audio_channels = 2;
    int audio_buffers = 4096;

    if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
    //printf("Unable to open audio!\n");
    exit(1);
    }
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
    if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
    //printf("Unable to open audio!\n");
    exit(1);
    }

    music = Mix_LoadWAV(soundfile);

}

void myaudio::musicDone()
{
    music = NULL;
    Mix_CloseAudio();
}

void myaudio::play()
{
    Mix_PlayChannel(-1, music, 0);
}

void myaudio::playloop()
{
    Mix_PlayChannel(-1, music, -1);
}

